package cn.auto.controller;

import java.util.HashMap;
import java.util.List;

import com.jfinal.core.ActionKey;

import cn.auto.service.SuiteService;
import cn.auto.utility.HelperController;
import cn.auto.utility.Status;
import cn.auto.utility.Utilities;
import net.sf.json.JSONObject;

public class SuiteController extends HelperController {
	
	SuiteService service=new SuiteService();
	
	public void index() {
		String pid=getPara("pid");
		HashMap<Object, Object> result=service.getSuites(pid);
		String st = (String) result.get("status"); 
		HashMap<String, String> msg=new HashMap<>();
		msg.put(Status.SUCCESS, "获取成功!");
		msg.put(Status.NORECORD, "无记录!");
		msg.put(Status.FAILED, "获取失败!");
		responseResult(st, msg, (List<?>)result.get("body"));
	}
	
	@ActionKey("/suite/add")
	public void addModule() {
		JSONObject jo = readRequstJson();
		HashMap<String, String> addInfo = Utilities.jsonToHashMap(jo);
		String st = service.addSuite(addInfo);
		String[] msg = { "添加模块成功!", "添加模块失败!" };
		responseResult(st, msg);
	}
	
	@ActionKey("/suite/del")
	public void delModule() {
		String sid=getPara("sid");
		String st = service.removeSuite(sid);
		String[] msg = { "删除模块成功!", "删除模块失败!" };
		responseResult(st, msg);
	}	
	
}
